import Request from './pocky-request/index';

//文档
//https://www.yuque.com/pocky/aaeyux/irx7u0

export default { 
	
    // post 请求， 200 响应码
    post(url, data) {
		
		
		let r = Request();
		
		let reqId = r.interceptors.scoped.request.use(
		    (config) => {
		        //console.log('is scoped request');
		
		        return config;
		    },
		    (err) => {
		        //console.error('scoped request: ', err);
		
		        return false;
		    }
		);
		
		let repId = r.interceptors.scoped.response.use(
		    (res, config) => {				
				
				if (res.statusCode === 200) {					
					if (res.data.code > 0) {										
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon:'none'
						})						
						return false
					} else if (res.data.code === -1) {
						uni.navigateTo({
							url: '../everyone/login'
						})
						return false
					}					
				} else {
					uni.showToast({
						title: '网络出错',
						icon: 'none'
					});
					return false					
				}	
					
		        return res;
		    },
		    (err) => {
		        //console.error('scoped response: ', err);		
		        return Promise.reject(err);
		    }
		);
		
		
        return r.post(url, {
            header: {
                contentType: 'application/json',
				'tk-token' : uni.getStorageSync('token')
            },
            data: data
        });
    }
 
};
